package com.wing.productionPlan.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.productionPlan.model.entity.RequirePlanProduct;
import com.wing.productionPlan.model.response.RequirePlanItermVO;
import com.wing.productionPlan.model.response.RequirePlanProductVO;
import com.wing.productionPlan.service.RequirePlanIProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Validated
@Api(value = "Admin-生产管理-产品需求汇总", tags = "#/product/requirePlan/requirePlanProductSummeryList")
@RestController("RequirePlanProductSummaryController")
@RequestMapping("productionPlan/admin/requirePlanProductSummary")
@RequiredArgsConstructor
public class RequirePlanProductSummaryController {


    private final RequirePlanIProductService requirePlanIProductService;

    @ApiOperation(value = "查询产品需求汇总列表", notes = "搜索-任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public  PageResult  selectRequirePlanProductList(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String materialDescribe
            ,String materialCode
            ,String startTime
            ,String endTime
    ) {
        Page<RequirePlanProduct> pg = new Page<>(page, limit);
        HashMap map = new HashMap();
        map.put("materialDescribe", materialDescribe);
        map.put("materialCode", materialCode);
        map.put("startTime", startTime);
        map.put("endTime", endTime);

        Map<String, Object> datas =  requirePlanIProductService.selProductSummaryData(map,page,limit);

        return new PageResult<>((List<Map<String, Object>>)datas.get("data"), Long.valueOf(datas.get("totalCount").toString()));
    }


    @ApiOperation(value = "查询产品需求汇总列表", notes = "搜索-任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/listHeads")
    public Map<String, Object>  listHeads(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String materialDescribe
            ,String materialCode
            ,String startTime
            ,String endTime
    ) {
        HashMap map = new HashMap();
        map.put("materialDescribe", materialDescribe);
        map.put("materialCode", materialCode);
        map.put("startTime", startTime);
        map.put("endTime", endTime);

        Map<String, Object> datas =  requirePlanIProductService.selProductSummaryDataHeads(map,page,limit);
        return datas;
    }

}
